/***************************************************************************
 *   Copyright (C) 2007 by crackedmind                                     *
 *   digital.stream.of.mind@gmail.com                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef JAMFS_FILESYSTEM_HPP_INCLUDED
#define JAMFS_FILESYSTEM_HPP_INCLUDED

namespace jamfs
{
    class IFolder;
    class IFile;

    typedef std::map<std::string,IFolder*> __reged_folders_map;

    enum FileMode_e
    {
        JAMFS_READ   = (1<<0),
        JAMFS_WRITE  = (1<<1),
        JAMFS_BINARY = (1<<2)
    };

    class MODULE_EXPORT Filesystem
    {
    private:
        typedef struct _mount_point {
            std::string dir;
            std::string folder;
            std::string type;
        };

        const char* __config_file;


        uint8_t __log_level;
        std::vector<SharedLibrary*> __loaded_plugins;
        std::vector<_mount_point*>  __mounted_points;
        
        __reged_folders_map __reged_folders;

        uint32_t __last_error_mode;

    private:
        Filesystem();
        Filesystem(const Filesystem&);
        Filesystem& operator=(const Filesystem&);

        bool plugin_exist ( const char* filename);
    public:
        Filesystem(uint8_t log_level, const char *config_file = "jamfs.xml");
        ~Filesystem();

        bool process_config ();

        bool register_folder ( IFolder *folder);
        bool unregister_folder ( IFolder *folder);

        bool mount ( const char *dir, const char *folder, const char *type );
        
        // node may be a dir or a folder
        bool umount ( const char *node );

        IFile *open ( const char *filename, uint8_t mode);
        void close (IFile *file);
    };
}

#endif // JAMFS_FILESYSTEM_HPP_INCLUDED
